package service.impl.v2;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import dao.v2.ConfigVOMapper;
import dao.v2.MemberTicketVOMapper;
import dao.v2.MemberVOMapper;
import dao.v2.MessageVOMapper;
import dao.v2.OrderVOMapper;
import model.LogEarnVO;
import model.MemberVO;
import model.OrderPayVO;
import model.OrderVO;
import net.sf.json.JSONArray;
import service.v2.MemberService;
import service.v2.MoneyService;
import service.v2.OrderService;
import service.v2.PushInterService;
import service.v2.WeChatService;
import util.NumberUtil;
import util.PushUtil;
import util.WeixinUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@Service
public class PushInterServiceImpl implements PushInterService {
	
	@Autowired
	private MemberVOMapper memberDao;
	@Autowired
	private WeChatService wechatservice;
	@Autowired
	private ConfigVOMapper configvomapper;
	@Autowired
	private MemberService memberService;
	@Autowired
	private MemberTicketVOMapper memberTicketVOMapper;
	@Autowired
	private MoneyService moneyService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private OrderVOMapper orderVOMapper;
	@Autowired
	private MessageVOMapper msgDao;
	
	/*
	 *余额充值 公众号推送
	 */
	public void pushBalanceRecharge(MemberVO membervo, OrderPayVO payVO) {
		final String  free_cash = membervo.getFree_cash_en();
		final String  total_price = payVO.getTotal_price();
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String member_id = membervo.getId();
		JSONObject obj = JSON.parseObject(payVO.getParams());
		final String lang =obj.getString("lang");
		
		new Thread(new Runnable() {
			public void run() {
				
			StringBuffer buffer = new StringBuffer();
			buffer.append("账户充值").append("\n\n");	
			buffer.append("恭喜您成功充值：US $"+total_price).append("\n");	
			buffer.append("充值后余额：US $"+free_cash).append("\n\n");	
			buffer.append("<a href=\""+world_uniposts_url+"/#/account_account\">>>点击查看我的账户余额</a>");	
			String content =buffer.toString();
			wechatservice.sendWeChatMsgCommonMethod(member_id,content);
			}
		}).start();
		
	}
	/*
	 *电子提货券购买 公众号推送
	 */
	@Override
	public void pushMemberTicket(String member_id, String rate, String ticket, String country) {
		final String memberId = member_id;
		final String rate_ = rate;
		final String ticket_ = ticket;
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");
		final int use_tickets=memberTicketVOMapper.selectUseTickets(memberId);	
		
		new Thread(new Runnable() {
			public void run() {
			
			StringBuffer buffer = new StringBuffer();
			buffer.append(ticket_name+"购买！").append("\n\n");	
			double rate1 =Double.parseDouble(rate_);
			String rate2=rate_;
			//小数点处理 不到1元进一
			if(rate1<1 && rate1>0){
				rate1=rate1*10;
				buffer.append("恭喜您成功购买 "+ticket_+ticket_name+"("+rate1+"折)").append("\n");	
			}else{
				rate2=(NumberUtil.formatDouble((int)rate1,0));
				buffer.append("恭喜您成功购买 "+ticket_+"("+rate2+"折)").append("\n");	
			}
			buffer.append("可交易"+ticket_name+"余额："+use_tickets).append("\n\n");	
			buffer.append("<a href=\""+world_uniposts_url+"/#/ticket_ticket\">>>点击查看我的"+ticket_name+"</a>");	
			String content_ =buffer.toString();
			
			wechatservice.sendWeChatMsgCommonMethod(memberId,content_);
			System.out.println("电子提货券购买 公众号推送");
			}
		}).start();
	}
	/*
	 * 电子提货券充值 分润推送   个推&公众号
	 */
	@Override
	public void rechargeTicket(String conn_no, String member_id, String country) {
		final String connNo = conn_no;
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String member_id_ = member_id;
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final List<String> member_list =  memberService.getShangXianMemberId(connNo);
		
		//公众号 
				new Thread(new Runnable() {
					public void run() {
						String nick_name = memberService.getNickName(member_id_);
						if(member_list.size()!=0){
							for(int i=0;i<member_list.size();i++){
								if(member_list.get(i)!=null){
									List<LogEarnVO> list = moneyService.selectRechargeTicketAwardList(member_list.get(i),connNo);//
									for(int j=0; j<list.size();j++){
										StringBuffer buffer = new StringBuffer();
										if(("2".equals(list.get(j).getAward())) || (list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ){
											//活力奖（2）+助理奖（3）
											buffer.append("您有一笔收益！").append("\n\n");	
											buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
											buffer.append("对方账号："+nick_name).append("\n");	
											buffer.append("获得收益：US $"+list.get(j).getEarn_money()
													+"(本金US $"+list.get(j).getCapital_cash()
													+"+利润US $"+list.get(j).getProfit_cash()
													+"+购物专用金US $"+list.get(j).getBuy_cash()+")").append("\n\n");	
											buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
											String content =buffer.toString();
											wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
										}else if("4".equals(list.get(j).getAward())){
											buffer.append("您有一笔收益！").append("\n\n");	
											buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
											buffer.append("对方账号："+nick_name).append("\n");	
											buffer.append("获得收益：US $"+list.get(j).getEarn_money()
													+"(利润US $"+list.get(j).getProfit_cash()
													+"+购物专用金US $"+list.get(j).getBuy_cash()+")").append("\n\n");	
											buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
											String content =buffer.toString();
											wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
										}else{
											buffer.append("您有一笔收益！").append("\n\n");	
											buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
											buffer.append("对方账号："+nick_name).append("\n");	
											buffer.append("获得收益：US $"+list.get(j).getEarn_money()).append("\n\n");	
											buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
											String content =buffer.toString();
											wechatservice.sendWeChatMsgCommonMethod(member_list.get(i),content);
										}
										System.out.println("电子提货券充值 分润推送  公众号");
									}
								}
							}
						}
					}
				}).start();
	}
	/*
	 * 订单支付推送  公众号
	 */
	@Override
	public void pushOrderPay(List<OrderVO> orderList, String country) {
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");

		new Thread(new Runnable() {
			public void run() {
				for(int i=0;i<orderList.size();i++){
					OrderVO orderVO=orderList.get(i);
					String good_name= orderService.getOrderGoodName(orderVO.getId());
					DecimalFormat  df = new DecimalFormat("######0.00");   
					String str="["+orderVO.getAddress_content()+"]";
					JSONArray jsonArray =JSONArray.fromObject(str);
					String address=(String) jsonArray.getJSONObject(0).get("country")+","
							+(String) jsonArray.getJSONObject(0).get("province")+","
							+(String) jsonArray.getJSONObject(0).get("city")+","
							+(String) jsonArray.getJSONObject(0).get("apt")+","
							+(String) jsonArray.getJSONObject(0).get("address");
					StringBuffer buffer = new StringBuffer();
					buffer.append("【"+app_name+"】订单支付成功！").append("\n\n");	
					//现金+商票
					if(!"0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：US $"+total_price+"+"+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					//现金
					if(!"0".equals(orderVO.getTotal_price())&&"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：US $"+total_price).append("\n");	
					}
					//商票
					if("0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						buffer.append("订单金额："+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					if(good_name.length()>15){
						good_name = good_name.substring(0, 14)+"...";
						buffer.append("购买商品："+good_name).append("\n");	
					}else{
						buffer.append("购买商品："+good_name).append("\n");	
					}
					buffer.append("收货信息："+jsonArray.getJSONObject(0).get("name")+","+jsonArray.getJSONObject(0).get("tel")+","+address).append("\n");	
					buffer.append("订单编号："+orderVO.getNo()).append("\n\n");	
					buffer.append("<a href=\""+world_uniposts_url+"/#/orderDetail?order_id="+orderVO.getId()+"\">>>查看详情</a>");	
					String content =buffer.toString();
					wechatservice.sendWeChatMsgCommonMethod(orderVO.getCreate_by(),content);
				}
			}
		}).start();
		
	}
	/*
	 * 只买东西时分润推送
	 */
	@Override
	public void BuyGoodsProfit(String orderId, String country) {
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String order_id = orderId;
		final OrderVO orderVO = orderVOMapper.getOrderById(order_id);
		final String nick_name=memberService.getNickName(orderVO.getCreate_by());
		
		List<String> member_list =memberService.getShangXianMemberIdByOrderId(orderId);
		if(member_list.size()!=0){
			for(int i=0;i<member_list.size();i++){
				if(member_list.get(i)!=null){
					final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectBuyGoodsProfitAwardList(member_list.get(i),orderId);//
					//个推
					final String memberId=member_list.get(i);
				

					//公众号
					/*new Thread(new Runnable() {
						public void run() {*/
							if("3".equals(orderVO.getState()) || "4".equals(orderVO.getState())){
								for(int  j=0; j<list.size();j++){
									double rate_cash=Double.parseDouble(moneyService.getRateCash(list.get(j).getId()));
									
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(本金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getCapital_cash())*rate_cash, 2)
												+"+利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)
												+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)
												+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()+"(待结算)").append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)).append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_waitCash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("只买东西时分润推送 公众号");
								}
							}
						/*}
					}).start();*/
				}
			}
		}
		
	}
	/*
	 * 买套餐分润推送 (商品)
	 */
	@Override
	public void BuyGoodsPackageProfitByOrderId(String orderId, String country) {
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String order_id = orderId;
		
		ArrayList<LogEarnVO> places = new ArrayList<LogEarnVO>();
	
		if(orderId !=null){
			OrderVO orderVO = orderVOMapper.getOrderById(orderId);
			final String nick_name=memberService.getNickName(orderVO.getCreate_by());
			List<String> member_list =memberService.getShangXianMemberIdByOrderId(order_id);
			if(member_list.size()!=0){
				for(int i=0;i<member_list.size();i++){
					if(member_list.get(i)!=null){
						final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectBuyGoodsPackageProfitAwardList(member_list.get(i),order_id);//
						
						final String memberId=member_list.get(i);
						
						//公众号
						new Thread(new Runnable() {
							public void run() {
								for(int j=0; j<list.size();j++){
									double rate_cash=Double.parseDouble(moneyService.getRateCash(list.get(j).getId()));
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+ NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(本金US $"+ NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getCapital_cash())*rate_cash, 2)
												
												+"+利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+ NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+ NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)).append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("买套餐分润推送 (商品)推送 公众号");
								}
							}
						}).start();
					}
				}
			}
		}
	}
	/*
	 * 买套餐分润推送 (充劵)
	 */
	@Override
	public void BuyGoodsPackageProfitByConn_no(String conn_no, String country) {
		final String connNo = conn_no;
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
		ArrayList<LogEarnVO> places = new ArrayList<LogEarnVO>();
		String nick_name_=null;
		if(conn_no !=null){
			List<String> member_list = memberService.getShangXianMemberId(connNo);
			final String nick_name =nick_name_=memberService.getNickNameByConnNO(connNo);
			if(member_list.size()!=0){
				for(int i=0;i<member_list.size();i++){
					if(member_list.get(i)!=null){
						final List<LogEarnVO> list =(ArrayList<LogEarnVO>) moneyService.selectRechargeTicketAwardList(member_list.get(i),connNo);//
						final String memberId=member_list.get(i);
						
						//公众号
						new Thread(new Runnable() {
							public void run() {
								for(int j=0; j<list.size();j++){
									double rate_cash=Double.parseDouble(moneyService.getRateCash(list.get(j).getId()));
									
									StringBuffer buffer = new StringBuffer();
									if((list.get(j).getAward().indexOf("3,2")>-1) ||(list.get(j).getAward().indexOf("2,3")>-1) ||"2".equals(list.get(j).getAward())){
										//活力奖（2）+助理奖（3）
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(本金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getCapital_cash())*rate_cash, 2)
												+"+利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)
												+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else if("4".equals(list.get(j).getAward())){
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
												+"(利润US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getProfit_cash())*rate_cash, 2)
												+"+购物专用金US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getBuy_cash())*rate_cash, 2)
												+")").append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}else{
										buffer.append("您有一笔收益！").append("\n\n");	
										buffer.append("交易类型："+list.get(j).getAward_name()).append("\n");	
										buffer.append("对方账号："+nick_name).append("\n");	
										buffer.append("获得收益：US $"+NumberUtil.formatDoubleUp(Double.parseDouble(list.get(j).getEarn_money())*rate_cash, 2)
													  ).append("\n\n");	
										buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
										String content =buffer.toString();
										wechatservice.sendWeChatMsgCommonMethod(memberId,content);
									}
									System.out.println("买套餐分润推送 (充劵)推送 公众号");
								}
							}
						}).start();
					}
				}
			}
		}
		
	}
	/*
	 * 退款 公众号推送  个推推送
	 */
	@Override
	public void pushRefund(String total_price, String create_by, String pay_type, String country) {
		final String refund_fee = total_price;
		final String memberId = create_by;
		final String world_uniposts_url = configvomapper.loadConfig("WORLD_UNIPOSTS_URL");
		final String app_logo = configvomapper.loadConfig("APP_LOGO");
		final String app_name = configvomapper.loadConfig("APP_NAME");
		
			if(!"0.00".equals(refund_fee)){//不等于购物赚佣金
				new Thread(new Runnable() {
					public void run() {
						StringBuffer buffer = new StringBuffer();
						buffer.append("您有一笔收益！").append("\n\n");	
						buffer.append("交易类型：退款").append("\n");	
						buffer.append("获得收益：US $"+refund_fee).append("\n");	
						if("4".equals(pay_type)){
							//购物赚佣金
							buffer.append("<a href=\""+world_uniposts_url+"/#/account_buyCash\">>>查看详情</a>");	
						}else{
							buffer.append("<a href=\""+world_uniposts_url+"/#/account_cash\">>>查看详情</a>");	
						}
						String content =buffer.toString();
						wechatservice.sendWeChatMsgCommonMethod(memberId,content);
					}
				}).start();
			}
	}
	/*
	 * 买套餐订单支付 公众号
	 */
	@Override
	public void pushOrderPayOne(String id, String country) {
		final String order_id = id;
		final String app_name = configvomapper.loadConfig("APP_NAME");
		final String world_uniposts_url = configvomapper.loadConfig("WECHAT_HOST");
		final String ticket_name = configvomapper.loadConfig("TICKET_NAME");
		final OrderVO orderVO =orderService.getOrderById(order_id);
		final String good_name= orderService.getOrderGoodName(order_id);
		new Thread(new Runnable() {
			public void run() {
					
					DecimalFormat  df = new DecimalFormat("######0.00");   
					String str="["+orderVO.getAddress_content()+"]";
					JSONArray jsonArray =JSONArray.fromObject(str);
					String address=(String) jsonArray.getJSONObject(0).get("country")+","
							+(String) jsonArray.getJSONObject(0).get("province")+","
							+(String) jsonArray.getJSONObject(0).get("city")+","
							+(String) jsonArray.getJSONObject(0).get("apt")+","
							+(String) jsonArray.getJSONObject(0).get("address");
					StringBuffer buffer = new StringBuffer();
					buffer.append("【"+app_name+"】订单支付成功！").append("\n\n");	
					//现金+商票
					if(!"0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：US $"+total_price+"+"+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					//现金
					if(!"0".equals(orderVO.getTotal_price())&&"0".equals(orderVO.getTotal_ticket())){
						String total_price =df.format(Double.parseDouble(orderVO.getTotal_price())+Double.parseDouble(orderVO.getFreight()));
						buffer.append("订单金额：US $"+total_price).append("\n");	
					}
					//商票
					if("0".equals(orderVO.getTotal_price())&&!"0".equals(orderVO.getTotal_ticket())){
						buffer.append("订单金额："+orderVO.getTotal_ticket()+ticket_name).append("\n");	
					}
					if(good_name.length()>15){
						String good_name1 = good_name.substring(0, 14)+"...";
						buffer.append("购买商品："+good_name1).append("\n");	
					}else{
						buffer.append("购买商品："+good_name).append("\n");	
					}
					buffer.append("收货信息："+jsonArray.getJSONObject(0).get("name")+","+jsonArray.getJSONObject(0).get("tel")+","+address).append("\n");	
					buffer.append("订单编号："+orderVO.getNo()).append("\n\n");	
					buffer.append("<a href=\""+world_uniposts_url+"/#/orderDetail?order_id="+orderVO.getId()+"\">>>查看详情</a>");	
					String content =buffer.toString();
					wechatservice.sendWeChatMsgCommonMethod(orderVO.getCreate_by(),content);
				}
		}).start();
		
	}
	
	
}
